package org.entities;

import org.GameState;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Polygon;
import java.util.ArrayList;
import org.newdawn.slick.geom.Vector2f;
/*
 * A generic class for all tile objects
 *
 */

public abstract class LevelObject {

    GameState game;
    public float x;
    public float y;
    public String type;
    public Polygon poly;
    public ArrayList<LevelObject> downWall = new ArrayList<LevelObject>();
    public ArrayList<LevelObject> upWall = new ArrayList<LevelObject>();
    public ArrayList<LevelObject> rightWall = new ArrayList<LevelObject>();
    public ArrayList<LevelObject> leftWall = new ArrayList<LevelObject>();
    public ArrayList<LevelObject> playerBox = new ArrayList<LevelObject>();
    public ArrayList<LevelObject> free = new ArrayList<LevelObject>();
    public LevelObject temp;
    public Vector2f vec=new Vector2f(16,16);
    public boolean diagUp, diagDown; //are we on a slope/diagonal ?

    public LevelObject(
            int x, int y,
            int topLeftX, int topLeftY,
            int topRightX, int topRightY,
            int downRightX, int downRightY,
            int downLeftX, int downLeftY,
            String type) {


        this.x = x;
        this.y = y;
        this.type = type;

        poly = new Polygon(new float[]{
                    topLeftX, topLeftY,
                    topRightX, topRightY,
                    downRightX, downRightY,
                    downLeftX, downLeftY
                });
    }

    public String getType() {
        return type;
    }
    public void resetFlags(){
        diagDown=false;
        diagUp=false;
    }

    public abstract void update(int delta) throws SlickException;

    public abstract void draw(Graphics g);

    public boolean isCollisionWith(LevelObject other) {
        return poly.intersects(other.poly);
    }

    public boolean collidedWith(LevelObject entity) {
        return false;
    }
}

